package com.hissy.common.design.structure.component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangyanfei on 2019/4/10.
 *
 * @author zhangyanfei
 * @date 2019/04/10
 */
public class PayDemo {

    public abstract class Market {
        String name;

        public abstract void add(Market m);

        public abstract void remove(Market m);

        public abstract void payByCard();
    }

    /**
     * 分店
     */
    public class MarketBranch extends Market {

        /**
         * 加盟店列表
         */
        List<Market> list = new ArrayList<>();

        public MarketBranch(String s) {
            this.name = s;
        }

        @Override
        public void add(Market m) {
            list.add(m);
        }

        @Override
        public void remove(Market m) {
            list.remove(m);
        }

        // 消费之后，该分店下的加盟店自动累加积分
        @Override
        public void payByCard() {
            System.out.println(name + "消费,积分已累加入该会员卡");
            for (Market m : list) {
                m.payByCard();
            }
        }
    }

    public class MarketJoin extends Market {

        public MarketJoin(String s) {
            this.name = s;

        }

        @Override
        public void add(Market m) {

        }

        @Override
        public void remove(Market m) {

        }

        @Override
        public void payByCard() {
            System.out.println(name + "消费,积分已累加入该会员卡");
        }
    }
}
